package falling
{
	import flash.display.BitmapData;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import org.flixel.*;
	/**
	 * ...
	 * @author morgan
	 */
	public class Girl extends FlxSprite
	{
		[Embed (source = "../../data/falling/1_girl.png")] private var img_wat:Class;
		[Embed (source = "../../data/falling/1_girl_overlay.png")] private var img_over:Class;
		[Embed (source = "../../data/falling/1_girl_glow.png")] private var img_glow:Class;
		
		public var time:Number = 0;
		public var cliff:FlxSprite;
		public var selected:Number = 0;
		
		public var over:BitmapData;
		public var glow:BitmapData;
		
		public function Girl(x:int, y:int, cliff:FlxSprite) 
		{
			super(x, y, img_wat);
			this.cliff = cliff;
			over = FlxG.addBitmap(img_over);
			glow = FlxG.addBitmap(img_glow);
		}
		
		override public function update():void 
		{
			super.update();
			time += FlxG.elapsed;
			var dx:Number = FlxG.mouse.x - (x + width / 2);
			var dy:Number = FlxG.mouse.y - (y + height / 2);
			var dist:Number = dx * dx + dy * dy;
			if (dist < 40 * 40 && time > 24)
			{
				selected = Math.min(selected + FlxG.elapsed, 2.0);
			}
			
			if (time > 22)
			{
				alpha += FlxG.elapsed;
				(FlxG.state as FallingState1).text4.clearingToWord = 99;
			}
			alpha = Math.min(alpha, 2 - Math.max(selected, 1));
			
			velocity.x = cliff.velocity.x;
			velocity.y = cliff.velocity.y;
		}
		
		override public function draw():void 
		{
			FlxG.camera.buffer.draw(glow, new Matrix(1, 0, 0, 1, x - 10, y - 10), new ColorTransform(1, 1, 1, selected / 2),"overlay");
			super.draw();
			FlxG.camera.buffer.draw(over, new Matrix(1, 0, 0, 1, x, y), new ColorTransform(1, 1, 1, Math.max(selected - 1, 0)));
		}
		
	}

}